﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.InteropServices;

public partial class AutoScan_EveryDayDo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            lblHaveDo.Text = "每天凌晨12点10分仅运行1次，运行检测中";
            
            //if (DateTime.Now.ToString("HH-mm") == "00-10" && lblHaveDo.Text == "每天凌晨12点10分仅运行1次，今天未运行")
            if (DateTime.Now.ToString("HH-mm") == "00-10")
            {
                //执行逻辑
                //初始化日程提醒表中除了（不重复）的（有效期外）记录外的状态；

                Cisoft.Cisoft3G.BLL.RemindBO Remindbll = new Cisoft.Cisoft3G.BLL.RemindBO();

                string strwhereforneed = "";
                //开始时间小于等于当前时间 类型从不 处理标识0
                //开始时间小于等于当前时间 结束时间大于等于当前时间 类型结束之前 处理标识0
                //(RM_StartTime <= getdate() and RM_EndType=0 and RM_Status=0)or (RM_StartTime <= getdate() and RM_EndType=1 and RM_Status=0 and RM_EndTime >= getdate())
                strwhereforneed += " (RM_StartTime <= '" + DateTime.Now.ToString() + "'";
                strwhereforneed += " and RM_EndType=0 and RM_Status=1)";
                strwhereforneed += " or";
                strwhereforneed += " (RM_StartTime <= '" + DateTime.Now.ToString() + "'";
                strwhereforneed += " and RM_EndType=1 and RM_Status=1";
                strwhereforneed += " and RM_EndTime >= '" + DateTime.Now.ToString() + "')";


                List<Cisoft.Cisoft3G.Model.RemindMO> RemindmodelList = Remindbll.GetModelList(strwhereforneed);
                foreach (Cisoft.Cisoft3G.Model.RemindMO Remindmo in RemindmodelList)
                {
                    //根据频率类型进行发送
                    if (Remindmo.RM_RateType != 0)
                    {
                        //已处理 重置为0
                        Remindmo.RM_Status = 0;
                        Remindbll.Update(Remindmo);
                    }

                }


                //lblHaveDo.Text = "每天凌晨12点10分仅运行1次，今天已运行";
            }
        }
    }
}
